import algorithms.*;
import utils.OrderChecker;
import utils.RandomGenerator;
import utils.Timer;

import java.io.*;
import java.lang.reflect.Array;
import java.util.Arrays;

public class main{
    public static void main(String[] args) throws IOException, InterruptedException {

        // 从random.txt中读取数据
        RandomGenerator rg = new RandomGenerator();
        // rg.generateRandomNumbers(1000, "src/main/resources/large_random.txt");
        int[] random_data = readData("src/main/resources/random.txt");
        // int[] random_large_data = readData("src/main/resources/large_random.txt");

        int[] ses_result = Timer.time(new SerialEnumSort(), random_data, 1);
       int[] sms_result = Timer.time(new SerialMergeSort(), random_data, 1);
       int[] sqs_result = Timer.time(new SerialQuickSort(), random_data, 1);
        int[] pes_result = Timer.time(new ParallelEnumSort(), random_data, 1);
       int[] pms_result = Timer.time(new ParallelMergeSort(), random_data, 1);
       int[] pqs_result = Timer.time(new ParallelQuickSort(), random_data, 1);

       storeData(ses_result, "src/main/resources/order1.txt");
       storeData(sms_result, "src/main/resources/order2.txt");
       storeData(sqs_result,  "src/main/resources/order3.txt");
       storeData(pes_result, "src/main/resources/order4.txt");
       storeData(pms_result, "src/main/resources/order5.txt");
       storeData(pqs_result, "src/main/resources/order6.txt");


    }

    public static int[] readData(String path) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader(path));
        String line = in.readLine();
        String[] chunks = line.split(" ");
        int[] data = Arrays.stream(chunks).mapToInt(Integer::parseInt).toArray();
        in.close();
        return data;
    }

    public static void storeData(int[] data, String path) throws IOException {
        FileWriter writer = new FileWriter(path, false);
        for (int i=0; i<data.length-1; i++) {
            writer.write(data[i]+" ");
        }
        writer.write(Integer.toString(data[data.length-1]));
        writer.close();
        return;
    }
}